package cn.wolfcode.p2p.base.domain;

import cn.wolfcode.p2p.util.BitStatesUtils;
import lombok.Getter;
import lombok.Setter;

/**
 * 用户基本资料
 */
@Getter
@Setter
public class UserInfo extends BaseDomain {
    //版本号，用作乐观锁
    private Integer version = 0;
    //用户状态值
    private Long bitState = 0L;
    //用户实名值（冗余数据）
    private String realName;
    //用户身份证号（冗余数据）
    private String idNumber;
    //用户电话
    private String phoneNumber;
    //邮箱
    private String email;
    //收入
    private SystemDictionaryItem incomeGrade;
    //婚姻情况
    private SystemDictionaryItem marriage;
    //子女情况
    private SystemDictionaryItem kidCount;
    //学历
    private SystemDictionaryItem educationBackground;
    //住房条件
    private SystemDictionaryItem houseCondition;
    //实名认证对象id
    private Long realAuthId;
    //视频认证对象id
    private Long videoAuthId;

    //是否有借款在申请流程中
    public boolean hasBidRequestInProcess() {
        return BitStatesUtils.hasState(bitState, BitStatesUtils.HAS_BIDREQUEST_IN_PROCESS);
    }


    //判断用户是否完成了基本资料的填写--->是否有状态值
    public boolean hasBasicInfo() {
        return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BASIC_INFO);
    }

    //是否完成身份验证
    public boolean hasRealAuth() {
        return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_REAL_AUTH);
    }

    //是否完成视频验证
    public boolean hasVedioAuth() {
        return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_VEDIO_AUTH);
    }

    //是否满足以上的借款条件(3个)
    public boolean canBorrow() {
        return hasBasicInfo() && hasVedioAuth() && hasRealAuth();
    }

    //添加位状态,设置值
    public void addState(Long state) {
        long tempState = BitStatesUtils.addState(bitState, state);
        setBitState(tempState);
    }

    //移除位状态
    public void removeState(Long state) {
        long tempState = BitStatesUtils.removeState(bitState, state);
        setBitState(tempState);
    }
}
